<template>
    <div class="fillcontain">
        <div style="margin-top: 20px">已上课信息</div>
        <div class="table_container">
            <el-table
                :data="donelist"
                highlight-current-row
                style="width: 100%">
                <el-table-column
                    property="id"
                    label="全选"
                    min-width="5%">
                    <template slot-scope="scope">
                        <el-checkbox v-model="scope.row.checked"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column
                    property="id"
                    label="id"
                    min-width="5%">
                </el-table-column>
                <el-table-column
                    property="ename"
                    label="老师"
                    min-width="5%">
                </el-table-column>
                <el-table-column
                    property="shouldDay"
                    label="应上时间"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-date-picker size="mini" style="width: 120px"
                                        v-model="scope.row.shouldDay"
                                        align="right"
                                        type="date"
                                        value-format="timestamp"
                                        placeholder="开始日期"
                                        >
                        </el-date-picker>
                    </template>
                </el-table-column>
                <el-table-column
                    property="school"
                    label="实上时间"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-date-picker size="mini" style="width: 120px"
                                        v-model="scope.row.realDay"
                                        align="right"
                                        type="date"
                                        value-format="timestamp"
                                        placeholder="开始日期"
                                        >
                        </el-date-picker>
                    </template>
                </el-table-column>
                <el-table-column
                    property="subject"
                    label="课题"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.subject" size="mini" placeholder="请加课题"></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                    property="comments"
                    label="备注"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.comments" size="mini" placeholder="请加备注"></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                    property="periodname"
                    label="上课时段"
                    min-width="10%">
                </el-table-column>
                <el-table-column
                    property="teachers"
                    label="操作"
                    min-width="10%">
                    <template scope="scope">
                        <el-button @click="delDone(scope.$index,scope.row)" type="text" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-row style="margin-top: 20px">
                <el-col offset="20">
                    <el-button type="primary" size="small" @click="modifycheck">选择修改学生考勤</el-button>
                </el-col>
            </el-row>
            <div>请假信息</div>
            <el-table
                :data="leavelist"
                highlight-current-row
                style="width: 100%">
                <el-table-column
                    property="id"
                    label="全选"
                    min-width="5%">
                    <template slot-scope="scope">
                        <el-checkbox v-model="scope.row.checked"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column
                    property="id"
                    label="id"
                    min-width="10%">
                </el-table-column>
                <el-table-column
                    property="ename"
                    label="老师"
                    min-width="10%">
                </el-table-column>
                <el-table-column
                    property="shouldDay"
                    label="应上时间"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-date-picker size="mini" style="width: 120px"
                                        v-model="scope.row.shouldDay"
                                        align="right"
                                        type="date"
                                        value-format="timestamp"
                                        placeholder="开始日期"
                                       >
                        </el-date-picker>
                    </template>
                </el-table-column>
                <el-table-column
                    property="realDay"
                    label="实上时间"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-date-picker size="mini" style="width: 120px"
                                        v-model="scope.row.realDay"
                                        align="right"
                                        type="date"
                                        value-format="timestamp"
                                        placeholder="实上日期"
                                       >
                        </el-date-picker>
                    </template>
                </el-table-column>
                <el-table-column
                    property="subject"
                    label="课题"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.subject" size="mini" placeholder="请假备注"></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                    property="comments"
                    label="请假原因"
                    min-width="15%">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.comments" size="mini" placeholder="请假备注"></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    min-width="10%">
                    <template scope="scope">
                        <el-button @click="delLeave(scope.$index,scope.row)" type="text" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-row style="margin-top: 20px">
                <el-col offset="20">
                    <el-button type="primary" size="small" @click="buke">选择学生补课</el-button>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
    import headTop from '../components/headTop'
    import {mapActions, mapState, mapGetters} from 'vuex'
    import {changeClassLog, changeClassList, queryUserAlreadyAndLeaveList,buke,updateCheckWork} from '@/api/getData'
    import ElButton from "../../node_modules/element-ui/packages/button/src/button.vue";
    import ElRow from "element-ui/packages/row/src/row";
    import ElCol from "element-ui/packages/col/src/col";

    export default {
        computed: {
            ...mapGetters(['schoolList', 'channelList', 'periodList', 'empschoolMap'])
        },
        data() {
            return {
                formData:{

                },
                donelist: [],
                leavelist: [],
                currentRow: null,
                offset: 0,
                limit: 20,
                count: 0,
                currentPage: 1,
            }
        },
        components: {
            ElCol,
            ElRow,
            ElButton,
            headTop,
        },
        created() {
            this.formData.uid = this.$route.params.uid;
8010
        },
        mounted(){
            this.formData.uid = this.$route.params.uid;
            this.initData();
        },
        methods: {
            async initData() {
                const v = await queryUserAlreadyAndLeaveList({"data": this.formData});
                if (v.success == true) {
                    this.count = v.data.totalCount;
                    const dlist = v.data.alreadyList;
                    const llist = v.data.leaveList;
                    this.tableData = [];
                    this.donelist=[];
                    dlist.forEach(item => {
                        const td = {};
                        td.id=item.id;
                        td.checked=false;
                        td.username = item.username;
                        td.ename = item.ename;
                        td.schoolname = item.schoolname;
                        td.subject = item.subject;
                        td.shouldDay = item.shouldDay;
                        td.realDay = item.realDay;
                        td.comment = item.comments;
                        td.summary = item.summary;
                        this.donelist.push(td);
                    }),
                        this.leavelist=[];
                        llist.forEach(item => {
                            const td = {};
                            td.id=item.id;
                            td.checked=false;
                            td.username = item.username;
                            td.ename = item.ename;
                            td.schoolname = item.schoolname;
                            td.subject = item.subject;
                            td.shouldDay = item.shouldDay;
                            td.realDay = item.realDay;
                            td.comment = item.comments;
                            td.summary = item.summary;

                            this.leavelist.push(td);
                        })

                }
            },


            async buke(index, row) {
              var list=  this.leavelist.filter(function(item){
                    return item.checked==true;
                })
                var data = {"data": list}
                await buke(data)
                this.$message({
                    type: 'success',
                    message: '补课成功'
                });
              this.initData();
            },
            async modifycheck(index, row) {
               var list= this.donelist.filter(function(item){
                    return item.checked==true;
                })
                var data = {"data": list}
                await updateCheckWork(data)
                this.$message({
                    type: 'success',
                    message: '修改成功'
                });
                this.initData();

            },
            async delDone(index, row) {
                var data = {"data": row.id}
                await deleteCheckWork(data)
                this.$message({
                    type: 'success',
                    message: '删除成功'
                });
                this.initData();
            },
            async delLeave(index, row) {
                var data = {"data": row.id}
                await
                    deleteCheckWork(data)
                this.$message({
                    type: 'success',
                    message: '删除成功'
                });
                this.initData();
            }
        },
    }
</script>

<style lang="less">
    @import '../style/mixin';

    .table_container {
        padding: 20px;
    }

    .describ {
        padding: 30px;
        font-size: 12px;
        padding: 0;
        margin: 0;
        list-style: none;
        font-style: normal;
        text-decoration: none;
        border: none;
        font-family: "Microsoft Yahei", sans-serif;
        -webkit-tap-highlight-color: transparent;
        -webkit-font-smoothing: antialiased
    }
</style>
